﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BrokerPresentation
{



/// <summary>
/// 
/// </summary>
public class ClientProxy : ServiceInterface
{
    private Broker broker;
    


    /// <summary>
    /// 
    /// </summary>
    public ClientProxy()
    {
        broker = new Broker();
    }



    /// <summary>
    /// 
    /// </summary>
    /// <param name="functionParamaters"></param>
    /// <returns></returns>
    public Object InvokeFunctionA(Object functionParamaters)
    {
        Object serializedRequest    = MarshalRequest(functionParamaters);
        Object serializedResponse   = SendRequest(serializedRequest);

        return UnmarshalResponse(serializedResponse);
    }   



    /// <summary>
    /// 
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    private Object MarshalRequest(Object request)
    {
        //Do something with (e.g. Serialize) the request here.
        Object serializedRequest = request;

        return serializedRequest;
    }



    /// <summary>
    /// 
    /// </summary>
    /// <param name="serializedRequest"></param>
    /// <returns></returns>
    private Object SendRequest(Object serializedRequest)
    {
        broker.LocateServer();

        Object response = broker.forwardRequest(serializedRequest);

        return response;
    }



    /// <summary>
    /// 
    /// </summary>
    /// <param name="serializedResponse"></param>
    /// <returns></returns>
    private Object UnmarshalResponse(Object serializedResponse)
    {
        //Do something (e.g. Deserialize) the response here.
        Object response = serializedResponse;

        return response;
    }
}

}